package ar.edu.caece.compiler.grammar.factories;

import ar.edu.caece.compiler.grammar.AbstractTokenVisitorFactory;
import ar.edu.caece.compiler.grammar.TokenVisitor;

public class OP2Factory extends AbstractTokenVisitorFactory {

	private static OP2Factory INSTANCE;
	
	private OP21Factory op21Factory;
	private OP22Factory op22Factory;
	private OP23Factory op23Factory;
	private OP24Factory op24Factory;
	
	public static OP2Factory getInstance() throws Exception {
		if(INSTANCE==null) INSTANCE = new OP2Factory();
		return INSTANCE;
	}
	
	private Initializer initializer = new Initializer() {
		
		@Override
		public void init() {
			initializer = NoOperationInitializer.getInstance();
			op21Factory = OP21Factory.getInstance();
			op22Factory = OP22Factory.getInstance();
			op23Factory = OP23Factory.getInstance();
			op24Factory = OP24Factory.getInstance();
		}
	};
	
	private OP2Factory() throws Exception {

	}
	
	@Override
	public TokenVisitor makeChainedVisitor(
			final TokenVisitor siguiente) throws Exception {
		initializer.init();

		return op21Factory.makeChainedVisitor(op22Factory.makeChainedVisitor(op23Factory.makeChainedVisitor(op24Factory.makeChainedVisitor(siguiente))));
	
	}
	@Override
	public TokenVisitor makeVisitor() throws Exception {
		initializer.init();

		return op21Factory.makeChainedVisitor(op22Factory.makeChainedVisitor(op23Factory.makeChainedVisitor(op24Factory.makeVisitor())));
	}
	
	
}
